<template>
  <div>
    <van-search
      class="search"
      v-model="value"
      show-action
      background="transparent"
      placeholder="请输入小区或地址"
    >
      <template #label>
        <div class="label" @click="getCity(citys)">
          <i>{{ citys.label }}</i>
          <!-- <van-icon name="arrow-down" /> -->
        </div>
        <span>|</span>
      </template>
      <template #action>
        <van-icon
          class="right"
          name="location-o"
          size="22"
          color="orange"
          @click="$router.push('/map')"
        >
        </van-icon>
      </template>
    </van-search>

    <keep-alive>
      <MySwiper :images="images"></MySwiper>
    </keep-alive>
    <!-- <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in images" :key="item.id">
        <img :src="'http://liufusong.top:8080' + item.imgSrc" alt="" />
      </van-swipe-item>
    </van-swipe> -->

    <van-grid :border="false" class="grid">
      <van-grid-item>
        <van-icon class="griditem" name="wap-home-o" size="26" color="orange" />
        <span>整租</span>
      </van-grid-item>
      <van-grid-item>
        <van-icon class="griditem" name="friends-o" size="26" color="orange" />
        <span>合租</span>
      </van-grid-item>
      <van-grid-item>
        <van-icon class="griditem" name="location-o" size="26" color="orange" />
        <span>地图找房</span>
      </van-grid-item>
      <van-grid-item>
        <van-icon class="griditem" name="guide-o" size="26" color="orange" />
        <span>去出租</span>
      </van-grid-item>
    </van-grid>

    <div class="group">
      <div class="title">
        <h4>租房小组</h4>
        <span><a href="#">更多</a></span>
      </div>
      <van-grid
        :gutter="10"
        direction="horizontal"
        :column-num="2"
        class="grids"
      >
        <van-grid-item :key="item.id" v-for="item in areas">
          <img :src="'http://liufusong.top:8080' + item.imgSrc" alt="" />
          <div>
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </van-grid-item>
      </van-grid>
    </div>
  </div>
</template>

<script>
import MySwiper from '@/components/my-swiper.vue'
import { getImages } from '@/api/swipe'
import { getArea } from '@/api/area'
import { setArea, getAreas } from '@/utils/storage'
export default {
  data() {
    return {
      images: [],
      areas: [],
      value: '',
      citys:
        JSON.parse(getAreas()) || {
          label: '安庆',
          pinyin: 'anqing',
          short: 'aq',
          value: 'AREA|b4e8be1a-2de2-e039'
        }
    }
  },
  async created() {
    const { data } = await getImages()
    // console.log(data)
    this.images = data.body

    const { data: res } = await getArea()
    // console.log(res)
    this.areas = res.body
  },
  methods: {
    getCity(city) {
      setArea(JSON.stringify(city))
      this.$router.push('/areas')
    }
  },
  components: { MySwiper }
}
</script>

<style scoped lang="less">
/* 引入第三方或自定义的字体图标样式 */
// @font-face {
//   font-family: 'my-icon';
//   src: url('../styles/iconfont/iconfont.ttf') format('truetype');
// }

// .my-icon {
//   font-family: 'my-icon';
// }

// .my-icon-extra::before {
//   content: '\e614';
// }

.search {
  margin-top: 10px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
  display: flex;
  flex: 1;
  .label {
    display: inline-block;
    i::after {
      content: '';
      position: relative;
      top: 12px;
      width: 0;
      height: 0;
      border-style: solid;

      border-width: 8px 5px 0 5px;
      border-color: #000 transparent transparent transparent;
    }
  }
  span {
    height: 100%;
    margin: 0 3px 0 8px;
    color: #ccc;
  }
  .right {
    width: 28px;
    height: 28px;
    border: 1px solid orange;
    text-align: center;
    line-height: 26px;
    border-radius: 50%;
  }
}

.grid {
  font-size: 12px;
  .griditem {
    width: 36px;
    height: 36px;
    text-align: center;
    line-height: 36px;
    background-color: rgb(249, 244, 235);
    border-radius: 50%;
    margin-bottom: 5px;
  }
}
.group {
  width: 100%;
  min-height: 200px;
  background-color: #f6f5f6;
  padding: 8px 12px;
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    a {
      font-size: 14px;
      color: #999;
    }
  }
  .grids {
    margin-top: 10px;
    img {
      width: 40px;
      height: 40px;
      margin-right: 8px;
    }
  }
}
</style>
